puts "INFO: Running script [info script] @ [exec date]\n"

if {![file exist $OUTPUTS_DIR/etm]} {
		file mkdir $OUTPUTS_DIR/etm
}


######################################################
# variable setting
######################################################

#recommend to generate PBA-based ETM, because GBA-based ETM has some known limitation
set_global timing_extract_model_slew_propagation_mode path_based_slew

# help in faster ETM generation
set_global timing_enable_timing_window_pessimism_removal false

# To model the waveform propagation impact in ETM, WFP based ETM is generated in PBA mode only
set_global timing_extract_model_enable_waveform_propagation true

# extract max_clock_tree_path/min_clock_tree_path attribute
set_global timing_extract_model_write_min_max_clock_tree_path true

# arc_based modeling of clock checks is more accurate and is recommended for use
set_global timing_extract_model_write_clock_checks_as_arc true

# not include clock latency and uncertainty during ETM characterization
set_global timing_extract_model_include_latency_and_uncertainty false

set all_views [all_analysis_views]
set setup_views_bkp [all_setup_analysis_views]
set hold_views_bkp [all_hold_analysis_views]
set_analysis_view -setup $all_views -hold $all_views



######################################################
# post-CTS ETM
######################################################
foreach view $all_views {
		do_extract_model ${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.postCTS.lib -pg -view $view
}

#######################################################
## pre-CTS ETM
#######################################################
#set_interactive_constraint_modes [all_constraint_modes -active]
#reset_propagated_clock [all_clocks]
#foreach_in_col clk_source [get_property [get_clock] sources] {
#		puts "INFO: reset_propagated_clock [get_object_name $clk_source]"
#		reset_propagated_clock $clk_source
#}
#set_interactive_constraint_modes {}
#
#foreach view $all_views {
#		do_extract_model ${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.preCTS.lib -pg -view $view
#}
#
#
#######################################################
## Merge ETM
#######################################################
#foreach view $all_views {
#		merge_model_timing \
#		   -library_file "${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.preCTS.lib ${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.postCTS.lib" \
#		   -modes {preCTS postCTS} \
#		   -mode_group merged \
#		   -outfile ${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.merge.lib
#		gzip -f ${OUTPUTS_DIR}/etm/${DESIGN_NAME}.${view}.merge.lib
#}


set_analysis_view -setup $setup_views_bkp -hold $hold_views_bkp


puts "INFO: Completed script [info script]\n"


